#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Name : __init__.py
# Author: ls_seraph@126.com
# Time  : 2021/3/6 22:46

import xlrd


# 表格解析工具类
class ExcelUtil():
    def __init__(self, excel_path):
        self.excel_path = excel_path
        self.workbook = xlrd.open_workbook(excel_path)

    def __get_sheet_data(self, sheet_name):
        if sheet_name is None:
            sheet = self.workbook.sheet_by_index(0)
        else:
            sheet = self.workbook.sheet_by_name(sheet_name)
        return sheet

    def __get_row_count(self, sheet_name):
        row_count = self.__get_sheet_data(sheet_name).nrows
        return row_count

    def __get_col_count(self, sheet_name):
        col_count = self.__get_sheet_data(sheet_name).ncols
        return col_count

    def get_data_by_sheet(self, sheet_name):
        """:return: [["1","2"],["1","3"],["2","33"]]"""
        all_test_data = []
        for row_num in range(self.__get_row_count(sheet_name)):
            row_excel_data = []
            for col_num in range(self.__get_col_count(sheet_name)):
                row_excel_data.append(self.__get_sheet_data(sheet_name).cell_value(row_num, col_num))
            all_test_data.append(row_excel_data)
        return all_test_data
